package Bussiness;

import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Check 
{
    /**
     *Method to check Input-Name
     *@param String n
     *@return boolean true or false     
     */
    public static boolean checkName(String n)
    {      
        if (n==null||n.length()==0 || n=="") 
        	return false;
        else
        {
            String strPattern = "[^a-zA-Z ]$";           
            Pattern p; Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);          
            m=p.matcher(n);    
            return !m.find();
        }
    }    
    public static boolean checkSpace(String n)
    {
        
        
            String strPattern = "[^ ]";
            Pattern p; Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);
            m=p.matcher(n);
            return m.find();
        
    }
    
    /**
     *Method to check Email
     *@param String n
     *@return boolean true or false     
     */
    public static boolean checkEmail(String n)
    {
        if (n==null) 
        	return false;
        else
        {
            String strPattern = "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b";
            Pattern p; Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);
            m=p.matcher(n);
            return m.find();
        }
    }
        
    /**
     *Method to check Phone
     *@param String n
     *@return boolean true or false     
     */
    public static boolean checkPhone(String n)
    {
        if(n.equals(""))
            return true;
        if (n==null || n.length()>15 || n.length()<7) 
        	return false;
        else
        {
            String strPattern = "[^0-9]";
            Pattern p;Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);
            m = p.matcher(n);            
            return !m.find();
        }
    }
    
    public static boolean checkFloat(String n)
    {
        if (n==null||n.length()==0) 
        	return false;
        else
        {
            try {
                float num=0.0f;
                num=Float.parseFloat(n);
                if(num>0)
                    return true;
                else 
                    return false;
            } catch (NumberFormatException ex) {
                return false;
            }
            
        }
    }  
    public static boolean checkInt(String n)
    {
        if (n==null||n.length()==0) 
        	return false;
        else
        {
            try {
                int num=0;
                num=Integer.parseInt(n);
                if(num>=0)
                    return true;
                else 
                    return false;
            } catch (NumberFormatException ex) {
                return false;
            }
            
        }
    } 
      
    public static boolean checkID(String n)
    {
        if (n==null || n.length()==0) 
        	return false;
        else
        {
            String strPattern = "[^a-zA-Z0-9]";
            Pattern p;Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);
            m = p.matcher(n);            
            return !m.find();
           
        }
    }   
    /**
     *Method to check Date
     *@param String n
     *@return boolean true or false     
     */
    public static boolean _checkDate(String n)
    {
        if (n==null) 
        	return false;
        else
        {
            boolean flag=true;
            String dd,mm,yyyy;
            int d,m,y;
            yyyy=n.substring(0,4);
            mm=n.substring(5,7);
            dd=n.substring(8,10);
            try
            {
                    Date dat = new Date();
                    Calendar date = Calendar.getInstance();
                    date.setTime(dat); 
                    int y1=date.get(Calendar.YEAR);
	            m=Integer.parseInt(mm);
	            d=Integer.parseInt(dd);
	            y=Integer.parseInt(yyyy);
	            if ((d<1)&&(d>31))
	            	flag=false;
	            if ((m<1)&&(m>12))
	            	flag=false;   
                    
            }
            catch(Exception e)
            {
            	flag=false;
            }
            return flag;
        }
    }    
    
}
